home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Carousel
/
CAROUSEL.cdr
/
mactosh
/
utilprn
/
hpdeskje.sit
/
HPDJet ƒ
/
PACK.c
< prev
next >
Wrap
Text File
|
1989-04-02
|
11KB
|
411 lines
/* 02.04.1989 amn (latest edit) */
/* PACK.c - printer driver for Macintosh and HP DeskJet, Chooser interface. */
/*
Code for PACK ID -4096 to be used with the Chooser to set
the printing port options. Set the Flags longword in the PACK
resource to $0400E000 after building the PACK resource to make
sure we get the right-hand button message.
*/
/* Resources which are of standard types and accessed by this Chooser package */
/* have id# RESID_OWNED_BY_CHOOSER_PACK (-4080). (IM 4 says standard resource */
/* types to be used by this PACK resource should have IDs in the range -4080 */
/* to -4065.) */
/* Resources which are of non-standard types and/or belong to our driver code */
/* are accessed with RESID_OWNED_BY_PDEF (-8192). */
/* These include the 'Sntg' resource and our PREC #-8192 ???. */
/* Authors: Ari Mujunen (amn@hutcs.hut.fi) and Olli Arnberg (oar@hutcs.hut.fi). */
/* Copyright Ari Mujunen, Olli Arnberg 1989. */
/* You may redistribute the driver (=printer resource file, source files, */
/* documentation file(s), and the file 'Copyright and Source Offer') */
/* only _non-commercially_ and _in its entirety_. */
/* See the file 'Copyright and Source Offer' and/or documentation for details. */
/* Acknowledgements: Special thanks to Mr. Earle R. Horton for his 'Daisy' */
/* daisywheel printer driver and its source code published in 'MacTutor', Nov-Dec 1987. */
/* This driver served as a basis and inspiration for our work. It also */
/* proofed that a Macintosh printer driver can be done despite the lack of */
/* documentation from Apple. */
/* Change history: */
/* Version When Who Why */
/* 2.0 25.03.1989 amn,oar Original rewrite. */
/* 26.03.1989 amn Trying to make setting changes immediate. */
/* 28.03.1989 amn Settable printer origin. */
/* 31.03.1989 amn Gave up making immediate setting changes. */
/* 2.1 02.04.1989 amn,oar Released version. */
#include "common_mac_includes.h"
#include "prglobals.h"
/* Printer Setup Dialog box item numbers: */
#define MODEMBUTTON 3
#define PRINTERBUTTON 4
#define BAUDBUTTON 5
#define CTSBUTTON 6
#define XONXOFFBUTTON 7
#define INITSTR 8
#define TOPSTR 9
#define EOPSTR 10
#define EOFSTR 11
#define ORIGINTOPNUM 12
#define ORIGINLEFTNUM 13
#define DUMPRESOLUTIONBUTTON 14
#define MOVEBYWORDBOX 15
#define COMPATIBLEBOX 16
#define NUMSTRINGS 4
#define RESPAD 24
/* Type definitions: */
typedef struct tLabel {
int value;
char label[10];
} tLabel;
typedef struct tLabels {
int iNumberOfItems;
tLabel alternative[1];
} tLabels, **htLabels;
/* Prototypes: */
pascal OSErr
main(int, int, StringPtr, StringPtr, long, long);
void printerSetupDialog(void);
void retitleButton(DialogPtr, int, int *, htLabels);
int searchForValue(int, htLabels);
#define DIALOG_PTR_TYPE_TODAY DialogPtr
#include "dialog_item_handling.h"
/* Functions:*/
pascal OSErr
main(message, caller, objName, zoneName, p1, p2)
int message;
int caller;
StringPtr objName;
StringPtr zoneName;
long p1;
long p2;
{
if ((message == buttonMsg)
&& (caller == 1 /* Chooser is the caller */)
&& ((p2 & 0x000000FF) == 2 /* right button */)
) {
printerSetupDialog();
}
return (noErr); /* IM IV-218: "...always return noErr, except with select and deselect." */
} /* main */
#define REMOVE_PARTS_UNDER_DEVELOPMENT
void printerSetupDialog()
{
htSettings handleToCurrentSettings;
StringHandle userDefinablePrinterControlStrings;
htLabels baudLabels;
int currentNumberOfBaudAlternative;
htLabels resolutionLabels;
int currentNumberOfResolutionAlternative;
DialogPtr theDialog;
WindowPtr savePort;
int itemHit;
/* Fetch the current settings from our PRER file. */
/* According to IM V-432 it is the current resource file in PACK. */
if ((handleToCurrentSettings = (htSettings)(GetResource('Stng', RESID_OWNED_BY_PDEF))) == nil)
return;
if ((userDefinablePrinterControlStrings = (StringHandle)(GetResource('STR#', RESID_OWNED_BY_CHOOSER_PACK))) == nil)
return;
/* Fetch the baud and screen dump resolution button alternatives. */
if ((baudLabels = (htLabels)(GetResource('B89L', RESID_OWNED_BY_CHOOSER_PACK))) == nil)
return;
if ((resolutionLabels = (htLabels)(GetResource('B89L', RESID_OWNED_BY_CHOOSER_PACK+1))) == nil)
return;
/* Fetch the setup dialog. */
if ((theDialog = GetNewDialog(
RESID_OWNED_BY_CHOOSER_PACK,
nil,
(WindowPtr)(-1) /* in front of all windows */
)) == nil)
return;
/* Initialization of the dialog. */
pushRadioButton(
theDialog,
(((*handleToCurrentSettings)->port==0)?MODEMBUTTON:PRINTERBUTTON),
MODEMBUTTON,
PRINTERBUTTON
);
currentNumberOfBaudAlternative =
searchForValue(
(*handleToCurrentSettings)->baud,
baudLabels
);
retitleButton(
theDialog,
BAUDBUTTON,
¤tNumberOfBaudAlternative,
baudLabels
);
pushRadioButton(
theDialog,
(((*handleToCurrentSettings)->xonXoff)?XONXOFFBUTTON:CTSBUTTON),
CTSBUTTON,
XONXOFFBUTTON
);
setStringItemToInt(
theDialog,
ORIGINTOPNUM,
(*handleToCurrentSettings)->printerOrigin.v
);
setStringItemToInt(
theDialog,
ORIGINLEFTNUM,
(*handleToCurrentSettings)->printerOrigin.h
);
currentNumberOfResolutionAlternative =
searchForValue(
(*handleToCurrentSettings)->screenDumpResolution,
resolutionLabels
);
retitleButton(
theDialog,
DUMPRESOLUTIONBUTTON,
¤tNumberOfResolutionAlternative,
resolutionLabels
);
forceValueToControls(
theDialog,
(*handleToCurrentSettings)->useOnlyPCLLevel3Features,
COMPATIBLEBOX,
COMPATIBLEBOX
);
forceValueToControls(
theDialog,
(*handleToCurrentSettings)->movePrintPositionBeforeEachWord,
MOVEBYWORDBOX,
MOVEBYWORDBOX
);
#ifndef REMOVE_PARTS_UNDER_DEVELOPMENT
/* This gets the printer control strings from a string list,
then sets the editText items in the dialog box to contain
the strings.
*/
strptr = &((*mystrings)->thestrings[0]);
for (i=EOLITEM-1; EOFITEM - i++;) {
GetDItem(printdialog, i, &edittype, &edititem, &editbox);
SetIText(edititem, strptr);
strptr += (*strptr) + 1;
} /* for */
#endif
GetPort(&savePort);
SetPort(theDialog);
ShowWindow(theDialog);
frameButton(theDialog, OKBUTTON);
#ifndef REMOVE_PARTS_UNDER_DEVELOPMENT
PenSize(2, 2);
InsetRect(&baudbox, -3, -3);
FrameRoundRect(&baudbox, 12, 12);
#endif
itemHit = 0;
while (itemHit != OKBUTTON) {
ModalDialog(nil, &itemHit);
switch (itemHit) {
case BAUDBUTTON: /* Next baud rate into button */
currentNumberOfBaudAlternative++;
retitleButton(
theDialog,
BAUDBUTTON,
¤tNumberOfBaudAlternative,
baudLabels
);
break;
case DUMPRESOLUTIONBUTTON: /* Next resolution rate into button */
currentNumberOfResolutionAlternative++;
retitleButton(
theDialog,
DUMPRESOLUTIONBUTTON,
¤tNumberOfResolutionAlternative,
resolutionLabels
);
break;
case MODEMBUTTON:
case PRINTERBUTTON:
pushRadioButton(theDialog, itemHit, MODEMBUTTON, PRINTERBUTTON);
break;
case CTSBUTTON:
case XONXOFFBUTTON:
pushRadioButton(theDialog, itemHit, CTSBUTTON, XONXOFFBUTTON);
break;
case MOVEBYWORDBOX:
case COMPATIBLEBOX:
pushCheckBox(theDialog, itemHit);
break;
case CANCELBUTTON:
goto cleanUp;
break;
default:
break;
} /* switch */
} /* while */
/* User has clicked OK, we should read the dialog state */
/* and update 'Stng' and 'STR#' resources. */
(*handleToCurrentSettings)->port =
whichRadioButton(theDialog, MODEMBUTTON, PRINTERBUTTON);
(*handleToCurrentSettings)->baud =
(*baudLabels)->alternative[currentNumberOfBaudAlternative].value;
(*handleToCurrentSettings)->xonXoff =
whichRadioButton(theDialog, CTSBUTTON, XONXOFFBUTTON);
(*handleToCurrentSettings)->printerOrigin.v =
getStringItemAsInt(theDialog, ORIGINTOPNUM);
(*handleToCurrentSettings)->printerOrigin.h =
getStringItemAsInt(theDialog, ORIGINLEFTNUM);
(*handleToCurrentSettings)->screenDumpResolution =
(*resolutionLabels)->alternative[currentNumberOfResolutionAlternative].value;
(*handleToCurrentSettings)->useOnlyPCLLevel3Features =
controlIsOn(theDialog, COMPATIBLEBOX);
(*handleToCurrentSettings)->movePrintPositionBeforeEachWord =
controlIsOn(theDialog, MOVEBYWORDBOX);
ChangedResource(handleToCurrentSettings);
WriteResource(handleToCurrentSettings);
#ifndef REMOVE_PARTS_UNDER_DEVELOPMENT
/* First, determine the length. */
length = (long)(sizeof(int)+RESPAD);
for (i=EOLITEM-1; EOFITEM - i++;) {
GetDItem(printdialog, i, &edittype, &edititem, &editbox);
GetIText(edititem, thestring);
length += (long)thestring[0];
} /* for */
/* Size might have changed, so we unlock the handle and
attempt to resize it.
*/
asm {
move.l mystrings, a0 ;; save loading MacTraps
_HUnlock
move.l mystrings, a0
move.l length, d0
_SetHandleSize
move.l mystrings, a0
_GetHandleSize
move.l d0, result
}
if (result != length) { /* Abort on error */
DisposDialog(printdialog);
SetPort(tempport);
return(FALSE);
}
asm {
move.l mystrings, a0
_HNoPurge
move.l mystrings, a0
_HLock
}
/* Rebuild the STR# from item list. */
strptr = &((*mystrings)->thestrings[0]);
for (i=EOLITEM-1; EOFITEM - i++;) {
GetDItem(printdialog, i, &edittype, &edititem, &editbox);
GetIText(edititem, strptr);
strptr += (*strptr) + 1;
} /* for */
ChangedResource(mystrings);
WriteResource(mystrings);
#endif
/* Now the changes must be copied to the driver globals. */
/* Chooser has namely opened the driver _before_ it lets */
/* the user use this setup. */
/* Let's try this ingenious approach: reopen XPrint and */
/* let it figure out how to use the new settings. */
/* After all, they are _XPrint_ settings! */
/* Unfortunately Device Manager does not reopen us, at least not */
/* with System 4.2. */
/* Don't know what to do. */
#ifndef REMOVE_PARTS_UNDER_DEVELOPMENT
{
int weKnowAlreadyItIsTheSameAsIPrDrvrRef;
if (OpenDriver(sPrDrvr, &weKnowAlreadyItIsTheSameAsIPrDrvrRef) != noErr)
SysBeep(30); /* What else ??? */
}
#endif
cleanUp:
DisposDialog(theDialog);
SetPort(savePort);
} /* printerSetupDialog */
void retitleButton(theDialog, button, buttonCounter, labels)
DialogPtr theDialog;
int button;
int *buttonCounter;
htLabels labels;
{
int itemType;
Handle theItem;
Rect itemBox;
if ((*labels)->iNumberOfItems <= 0)
return;
if ((*buttonCounter < 0)
|| (*buttonCounter >= (*labels)->iNumberOfItems))
*buttonCounter = 0;
GetDItem(theDialog, button, &itemType, &theItem, &itemBox);
HLock(labels);
SetCTitle(theItem, (*labels)->alternative[*buttonCounter].label);
HUnlock(labels);
} /* retitleButton */
int searchForValue(value, labels)
int value;
htLabels labels;
{
int i;
for (i=0; i < ((*labels)->iNumberOfItems); i++)
if((*labels)->alternative[i].value == value)
return(i);
return(0);
} /* searchForValue */
#include "dialog_item_handling.c"